package com.xyhua.houseproperty.test;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class T {

    public static void main(String[] args) {
//        System.out.println(new File(".").getAbsolutePath());
        HashMap<String, Object> oo = CollUtil.newHashMap();
        oo.put("1", "aa");
        oo.put("2", "bb");
        Iterator<Map.Entry<String, Object>> iterator = oo.entrySet().iterator();
        String join = join(iterator, "&","","");
        System.out.println(join);
    }


    public static <T> String join(Iterator<T> iterator, CharSequence conjunction, String prefix, String suffix) {
        if (null == iterator) {
            return null;
        }

        final StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        T item;
        while (iterator.hasNext()) {
            if (isFirst) {
                isFirst = false;
            } else {
                sb.append(conjunction);
            }
            item = iterator.next();
            System.out.println(item.toString());
            if (item instanceof Iterator<?>) {
                sb.append(join((Iterator<?>) item, conjunction, prefix, suffix));
            } else {
                sb.append(StrUtil.wrap(String.valueOf(item), prefix, suffix));
            }
        }
        return sb.toString();
    }
}
